package leetcode.primary;

public class T169 {
    public int majorityElement(int[] nums) {
        int candNum = nums[0];
        int count  = 1;
        for (int i = 1; i < nums.length; i++) {
            if (candNum==nums[i]){
                count++;
            }else {
                count--;
            }

            if (count==0){
                candNum = nums[i];
                count = 1;
            }
        }
        return candNum;
    }

    public static void main(String[] args) {
        T169 t169 = new T169();
        System.out.println(t169.majorityElement(new int[]{2,2,1,1,1,2,2}));
    }
}
